<?php
if (!defined('APP_ID')) { die('No direct script access allowed'); }

/**
 * Input class
 */
class Input {
	/**
	 * Returns get variable(s)
	 */
	public static function get($offset = '', $clean = true) {
		$result = Arr::get($_GET, $offset, null);
		return self::clean($result, $clean);
	}

	/**
	 * Returns post variable(s)
	 */
	public static function post($offset = '', $clean = true) {
		$result = Arr::get($_POST, $offset, null);
		return self::clean($result, $clean);
	}

	/**
	 * Returns server variable(s)
	 */
	public static function server($offset = '', $clean = false) {
		$result = Arr::get($_SERVER, $offset, null);
		return self::clean($result, $clean);
	}

	/**
	 * Returns server variable(s)
	 */
	public static function clean($value, $clean = true) {
		if ($clean && !empty($value)) {
			$value = Security::clean($value);
		}
		return $value;
	}

	/**
	 * Returns request method in lowercase
	 */
	public static function getRequestMethod() {
		$result = null;

		if (isset($_SERVER['REQUEST_METHOD'])) {
			$result = trim(strtolower($_SERVER['REQUEST_METHOD']));
		}

		return $result;
	}

	/**
	 * Is postback
	 */
	public static function isPostBack() {
		$result = false;

		if (self::getRequestMethod() == 'post') {
			$result = true;
		}

		return $result;
	}

	/**
	 * Is running from command line?
	 */
	public static function isCli() {
		$result = false;

		if ((php_sapi_name() == 'cli') && ($_SERVER['argc'] >= 0)) {
			$result = true;
		}

		return $result;
	}
}